<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>会员列表-WeAdmin Frame型后台管理系统-WeAdmin 1.0</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
		<link rel="stylesheet" href="../../static/css/font.css">
		<link rel="stylesheet" href="../../static/css/weadmin.css">
		<!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
		<!--[if lt IE 9]>
	      <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
	      <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
	    <![endif]-->
	</head>

	<body>
		<div class="weadmin-nav">
			<span class="layui-breadcrumb">
        <a href="">首页</a>
        <a href="">报警管理</a>
        <a>
          <cite>历史报警</cite></a>
      </span>
			<a class="layui-btn layui-btn-sm" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
				<i class="layui-icon" style="line-height:30px">&#x1002;</i></a>
		</div>
		<div id="testText">
			<!-- zheli是文字 -->
		</div>
		<div class="weadmin-body">
			<div class="layui-row">
				<form class="layui-form layui-col-md12 we-search">
					报警查询：
					<div class="layui-inline">
						<input class="layui-input"  readonly="readonly" placeholder="起止日期" name="daterange" id="daterange">
					</div>
					<div class="layui-inline">
						<input type="text" lay-verify="required" name="stationname" placeholder="请输入站名" autocomplete="on" class="layui-input">
					</div>
					<button class="layui-btn" lay-submit lay-filter="search" ><i class="layui-icon">&#xe615;</i></button>
				</form>
			</div>
			<table class="layui-table" id="historylist" lay-filter="dealer">
			</table>
			</div>
		</div>

		<script src="../../lib/layui/layui.js" charset="utf-8"></script>
		<script src="../../static/js/date-format.js" type="text/javascript" charset="utf-8"></script>

		<script>
			var search = window.location.search;
			search = search.substring(1, search.length);
			var user = search.split("&")[0].split("=")[1];

			layui.extend({
				admin: '{/}../../static/js/admin'
			});

			layui.use(['laydate','jquery','admin','table', 'form'], function() {
				var laydate = layui.laydate,
					$ = layui.jquery,
					admin = layui.admin,
					table = layui.table,
					form = layui.form;

				//日期范围
				laydate.render({
					elem: '#daterange',
					range: true,
					value: DateFormat(new Date()) + " - " + DateFormat(new Date()),
				});

				form.on('submit(search)', function(data){
					stationName = data.field.stationname;
					table.render({
						elem: '#historylist',
						where: {DateRange: data.field.daterange, StationName: data.field.stationname, AlarmTypeId: -1, AlarmLevel: -1},
						url: 'WebHistoryAlarm.Lq', //数据接口
						page: true,
						even: true, //隔行背景
						cols: [[
							{field:'Id', title: 'Id', hide:true},
							{field:'Level', title: '报警级别', width:100, sort: true},
							{field:'DevName', title: '设备名', sort: true, templet:'<div>{{d.DeviceTypeName == null ? d.DeviceName : d.DeviceTypeName + "(" + d.DeviceName + ")"}}</div>'},
							{field:'Summary', title: '报警描述', sort: true},
							{field:'Info', title: '报警详情', sort: true},
							{field:'BeginTime', title: '开始时间', width:160, sort: true, templet:'<div>{{TimeFormat(d.BeginTime)}}</div>'},
							{field:'EndTime', title: '结束时间', width:160, sort: true, templet:'<div>{{d.IsVolatile == true ? "—— ——" : TimeFormat(d.EndTime)}}</div>'},
							// {field:'WebDealTime', title: '处理时间', width:160, templet:'<div>{{d.WebDealTime == "" ? "—— ——" : TimeFormat(d.WebDealTime)}}</div>'},
							{field:'WebDealer', title: '处理人'},
							{field:'WebAlarmReason', title: '原因', edit: 'text'},
						]],
					});

					return false;
				});

				var stationName;
				table.on('edit(dealer)', function(obj){
					var value = obj.value //得到修改后的值
    				,data = obj.data //得到所在行所有键值
    				,field = obj.field; //得到字段

					obj.update({
						WebDealer : user
					});

					$.ajax({
						type: "GET",
						url: "WebAlarmDealer.Lq",
						contentType: "application/json",
						accept: "application/json",
						data: {StationName:stationName, Id:data.Id, WebDealer:data.WebDealer, WebAlarmReason:data.WebAlarmReason},
						success: function(res) {
							var json = JSON.parse(res);
							if (json[0].Result == 'Success') {
								
								layer.msg("录入成功");
							} else {
								layer.msg("录入失败");
							}
						},
						error: function(XMLHttpRequest, textStatus, errorThrown) {
							layer.msg(textStatus);
						}
					});
				});
			});

			function DateFormat(d){
				var date = new Date(d);
				return date.Format("yyyy-MM-dd");
			}

			function TimeFormat(d) {
				var date = new Date(d);
				var min = new Date("0001-01-01T00:00:00");
				return date.getTime() == min.getTime() ? "" : date.Format("yyyy-MM-dd hh:mm:ss");
			}
		</script>
	</body>

</html>